package com.cuitrip.business.tripservice;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.cuitrip.apiservice.OrderBusiness;
import com.cuitrip.apiservice.TripBusiness;
import com.cuitrip.apiservice.model.ApiManager;
import com.cuitrip.app.MainApplication;
import com.cuitrip.app.base.UnitUtils;
import com.cuitrip.business.bill.ExplainActivity;
import com.cuitrip.business.bill.model.Rate;
import com.cuitrip.business.notice.model.FeeDescription;
import com.cuitrip.business.pay.model.PayMode;
import com.cuitrip.business.tripservice.event.ServiceChangeEvent;
import com.cuitrip.business.tripservice.model.FormType;
import com.cuitrip.business.tripservice.model.SelectMenu;
import com.cuitrip.business.tripservice.model.ServiceInfo;
import com.cuitrip.business.tripservice.proxy.PriceProxy;
import com.cuitrip.business.tripservice.ui.EditDetailLayout;
import com.cuitrip.business.tripservice.ui.SelectMenuFragment;
import com.cuitrip.business.tripservice.ui.SelectTwoMenuFragment;
import com.cuitrip.business.webview.H5UrlMaker;
import com.cuitrip.business.webview.proxy.WalletHelpDocProxy;
import com.cuitrip.business.webview.proxy.WebViewProxy;
import com.cuitrip.component.choicedialog.ChoiceDialog;
import com.cuitrip.component.choicedialog.MultiItem;
import com.cuitrip.component.item.ItemLayout;
import com.cuitrip.component.para.model.Para;
import com.cuitrip.component.para.proxy.ParaProxy;
import com.cuitrip.service.R;
import com.cuitrip.util.ResourceUtil;
import com.cuitrip.util.text.TextProxy;
import com.lab.app.customui.CustomUiConfig;
import com.lab.app.customui.CustomUiFragment;
import com.lab.network.model.CtApiResponse;
import com.lab.network.model.IProxyCallback;
import com.lab.network.model.ProxyResult;
import com.lab.network.proxy.ApiProxy;
import com.lab.rx.bus.RxBus;
import com.lab.utils.ArrayUtil;
import com.lab.utils.NumberUtils;
import com.lab.utils.ToastUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by sheena on 16/4/21.
 */
public class CreateTripPriceSettingFragment extends CustomUiFragment implements IProxyCallback {

    public static final int PAY_INCLUDE_TYPE = 0x01;
    public static final int PAY_EXCLUDE_TYPE = 0x02;
    public static final int PAY_TYPE = 0x03;
    public static final int PRICE_TYPE = 0x04;
    public static final int PAY_CURRENCY_TYPE = 0x05;

    private static final int ADVANCE_DAY = 7;
    private static final int TEXT_MAX_LIMIT = 500;
    @Bind(R.id.il_required)
    protected ItemLayout mOrderAdvanceNum;
    @Bind(R.id.il_duration)
    protected ItemLayout mOrderDuration;
    @Bind(R.id.il_capacity)
    protected ItemLayout mOrderPersonNumContent;
    @Bind(R.id.il_pricing_type)
    protected ItemLayout mOrderPricingType;
    @Bind(R.id.il_currency)
    protected ItemLayout mOrderCurrency;
    @Bind(R.id.tv_currency)
    protected TextView tvCurrency;
    @Bind(R.id.price_include_layout)
    EditDetailLayout priceIncludeLayout;
    @Bind(R.id.price_exclude_layout)
    EditDetailLayout priceExcludeLayout;
    @Bind(R.id.et_price)
    EditText mPayCountContent;
    @Bind(R.id.tv_unit)
    TextView mMoneyEndView;
    @Bind(R.id.fl_price_layout)
    FrameLayout mPriceLayout;
    private List<Integer> advanceDayList = new ArrayList<>();
    private List<SelectMenu> timeList = new ArrayList<>();
    private List<SelectMenu> minPeopleMenuList = new ArrayList<>();
    private List<SelectMenu> maxPeopleMenuList = new ArrayList<>();
    private ArrayList<CharSequence> includePayList = new ArrayList<>();
    private ArrayList<CharSequence> excludePayList = new ArrayList<>();
    private ApiProxy mApiProxy = new ApiProxy(this);
    private ServiceInfo mServiceInfo;
    private String priceType = "";
    private int mPayCount = 0;
    private ArrayList<FeeDescription> notice;
    private boolean isFirstClick = true;
    private String price = "";

    public static CreateTripPriceSettingFragment newInstance(ServiceInfo serviceInfo) {
        CreateTripPriceSettingFragment createTripPriceSettingFragment = new CreateTripPriceSettingFragment();
        Bundle bundle = new Bundle();
        bundle.putSerializable(ServiceInfo.KEY, serviceInfo);
        createTripPriceSettingFragment.setArguments(bundle);
        return createTripPriceSettingFragment;
    }

    public static String bindPersonNum(int minPeople, int maxPeople) {
        if (minPeople != maxPeople) {
            return minPeople + " - " + ResourceUtil.getString(R.string.trip_attribute_capacity_value_more, maxPeople);
        } else {
            String peopleText = TextProxy.getInstance().formatWithSingleAndMore(minPeople, R.string.trip_attribute_capacity_value_one, R.string.trip_attribute_capacity_value_more);
            return peopleText;
        }


    }

    @Override
    public boolean initCloseTopBar() {
        return false;
    }

    @Override
    public CustomUiConfig initCustomUiConfig() {
        CustomUiConfig config = new CustomUiConfig();
        config.mLeftStyle = CustomUiConfig.AreaStyle.ICON_STYLE;
        config.mTopbarLeftAreaName = getString(R.string.back_icon);
        config.mTopbarMiddleAreaName = getString(R.string.price);
        config.mRightStyle = CustomUiConfig.AreaStyle.ICON_STYLE;
        config.mTopbarRightAreaName = getString(R.string.query_icon);
        return config;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = super.onCreateView(inflater, container, savedInstanceState, R.layout.page_pay_instruction);
        Bundle bundle = getArguments();
        if (bundle != null) {
            mServiceInfo = (ServiceInfo) bundle.getSerializable(ServiceInfo.KEY);
        }
        return view;
    }

    @Override
    public void initView() {
        ButterKnife.bind(this, getView());
        mPayCountContent.setTypeface(MainApplication.getInstance().getIconFont());
        String moneyEnd = getString(R.string.trip_attribute_price_value_per_person);
        int index = moneyEnd.lastIndexOf("/");
        if (index >= 0) {
            moneyEnd = moneyEnd.substring(index, moneyEnd.length());
        }
        mMoneyEndView.setText(moneyEnd);
        initNavigation();
        initTitle();
    }

    private void initNavigation() {
        priceIncludeLayout.setNavigateAction(new EditDetailLayout.NavigateAction() {
            @Override
            public void navigate() {
                Bundle bundle = new Bundle();
                bundle.putString(ParaEditActivity.TITLE_KEY, getString(R.string.price_attribute_inclusion));
                bundle.putInt(ParaEditActivity.MAX_LIMIT_KEY, TEXT_MAX_LIMIT);
                if (!ArrayUtil.isNullOrEmpty(includePayList)) {
                    bundle.putCharSequenceArrayList(ParaEditActivity.PARA_KEY, includePayList);
                }
                Intent intent = new Intent(getContext(), ParaEditActivity.class);
                intent.putExtras(bundle);
                startActivityForResult(intent, PAY_INCLUDE_TYPE);
            }
        });

        priceExcludeLayout.setNavigateAction(new EditDetailLayout.NavigateAction() {
            @Override
            public void navigate() {
                Bundle bundle = new Bundle();
                bundle.putString(ParaEditActivity.TITLE_KEY, getString(R.string.price_attribute_exclusion));
                bundle.putInt(ParaEditActivity.MAX_LIMIT_KEY, TEXT_MAX_LIMIT);
                if (!ArrayUtil.isNullOrEmpty(excludePayList)) {
                    bundle.putCharSequenceArrayList(ParaEditActivity.PARA_KEY, excludePayList);
                }
                Intent intent = new Intent(getContext(), ParaEditActivity.class);
                intent.putExtras(bundle);
                startActivityForResult(intent, PAY_EXCLUDE_TYPE);
            }
        });

    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == Activity.RESULT_OK) {
            ArrayList<CharSequence> highList = data.getCharSequenceArrayListExtra(ParaEditActivity.PARA_KEY);
            if (requestCode == PAY_INCLUDE_TYPE) {
                includePayList.clear();
                if (!ArrayUtil.isNullOrEmpty(highList)) {
                    includePayList.addAll(highList);
                }
            } else if (requestCode == PAY_EXCLUDE_TYPE) {
                excludePayList.clear();
                if (!ArrayUtil.isNullOrEmpty(highList)) {
                    excludePayList.addAll(highList);
                }

            }
            setValueInContent(requestCode);
        }
    }

    @Override
    public void initData() {
        initAdvanceDayList();
        initDurationList();
        initPeopleList();
        initValues();
        updatePriceType();
        bindValueToLayout(PAY_TYPE, PRICE_TYPE, PAY_CURRENCY_TYPE, PAY_INCLUDE_TYPE, PAY_EXCLUDE_TYPE);
        TripBusiness.getInfoPages(mApiProxy, "1");

    }

    private void initTitle() {
        priceIncludeLayout.setTitle(getString(R.string.price_attribute_inclusion));
        priceExcludeLayout.setTitle(getString(R.string.price_attribute_exclusion));
    }

    public void initListener() {
        mPayCountContent.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
                if (i == EditorInfo.IME_ACTION_DONE) {
                    String payCount = textView.getText().toString();
                    mPayCount = (int) NumberUtils.parseFloat(payCount);
                    String formatPayCount = NumberUtils.getMoneyFormat(payCount);
                    textView.setText(formatPayCount);
                    mPayCountContent.setSelection(mPayCountContent.length());
                }
                return false;
            }
        });

        mPayCountContent.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (isFirstClick && hasFocus) {
                    startOtherPage();
                    isFirstClick = false;
                }
            }
        });

    }

    private void startOtherPage() {
        if (notice != null) {
            WebViewProxy.getInstance().browseWeb(getHostActivity(), WalletHelpDocProxy.formatUrl(H5UrlMaker.getWalletSettingPriceUrl()), false);
        }
    }

    @OnClick(R.id.il_required)
    public void setAdvanceRequired() {
        SelectMenuFragment selectMenuFragment = new SelectMenuFragment();
        List<SelectMenu> selectMenuList = new ArrayList<>();
        for (int i = 0; i < advanceDayList.size(); i++) {
            SelectMenu selectMenu = new SelectMenu();
            int dayValue = advanceDayList.get(i);
            selectMenu.key = String.valueOf(dayValue);
            if (dayValue > 1) {
                selectMenu.value = getString(R.string.trip_attribute_advance_value_more, dayValue);
            } else {
                selectMenu.value = getString(R.string.trip_attribute_advance_value_one, dayValue);
            }
            selectMenuList.add(selectMenu);
        }
        selectMenuFragment.setTitle(getString(R.string.trip_attribute_advance_desc));
        selectMenuFragment.setSelectMenuList(selectMenuList);
        showDialogFragment(selectMenuFragment);
        selectMenuFragment.setResultListener(new SelectMenuFragment.OnDataSelectBackListener() {
            @Override
            public void onSelect(SelectMenu selectMenu) {
                int advanceDay = Integer.parseInt(selectMenu.key);
                mServiceInfo.setPreOrderDays(advanceDay);
                bindPreOrderDays();
            }
        });
    }

    @OnClick(R.id.il_duration)
    public void setDuration() {
        SelectTwoMenuFragment selectTwoMenuFragment = new SelectTwoMenuFragment();
        selectTwoMenuFragment.setTitle(getString(R.string.trip_attribute_duration_desc));
        selectTwoMenuFragment.setOnDataSource(new SelectTwoMenuFragment.OnDataSource() {

            @Override
            public List<SelectMenu> onFirstSource() {
                return timeList;
            }

            @Override
            public List<SelectMenu> onSecondSource(int position, SelectMenu firstMenu) {
                List<SelectMenu> secondMenuList = new ArrayList<>();
                if (ArrayUtil.isIndexSafe(position + 1, timeList)) {
                    List<SelectMenu> subList = timeList.subList(position + 1, timeList.size());
                    secondMenuList.addAll(subList);
                    return secondMenuList;
                }
                return secondMenuList;
            }

        });
        selectTwoMenuFragment.setResultListener(new SelectTwoMenuFragment.OnTwoDataSelectBackListener() {
            @Override
            public void onSelect(SelectMenu firstSelectMenu, SelectMenu secondSelectMenu) {
                if (secondSelectMenu!=null) {
                    String duration = String.valueOf(Integer.parseInt(secondSelectMenu.key) - Integer.parseInt(firstSelectMenu.key));
                    String bestTime = firstSelectMenu.key;
                    mServiceInfo.setBestTime(bestTime);
                    mServiceInfo.setServiceTime(duration);
                    bindDuration();
                }
            }
        });
        showDialogFragment(selectTwoMenuFragment);
    }

    @OnClick(R.id.il_capacity)
    public void setCapacity() {
        SelectTwoMenuFragment selectTwoMenuFragment = new SelectTwoMenuFragment();
        selectTwoMenuFragment.setTitle(getString(R.string.trip_attribute_capacity_desc));
        selectTwoMenuFragment.setOnDataSource(new SelectTwoMenuFragment.OnDataSource() {

            @Override
            public List<SelectMenu> onFirstSource() {
                return minPeopleMenuList;
            }

            @Override
            public List<SelectMenu> onSecondSource(int position, SelectMenu firstMenu) {
                List<SelectMenu> secondMenuList = new ArrayList<>();
                if (ArrayUtil.isIndexSafe(position, maxPeopleMenuList)) {
                    int lastIndex = maxPeopleMenuList.size();
                    List<SelectMenu> subList = maxPeopleMenuList.subList(position, lastIndex);
                    secondMenuList.addAll(subList);
                    return secondMenuList;
                }
                return null;

            }

        });
        selectTwoMenuFragment.setResultListener(new SelectTwoMenuFragment.OnTwoDataSelectBackListener() {
            @Override
            public void onSelect(SelectMenu firstSelectMenu, SelectMenu secondSelectMenu) {
                int minPeople = Integer.parseInt(firstSelectMenu.key);
                int maxPeople = Integer.parseInt(secondSelectMenu.key);
                mServiceInfo.setMinBuyerNum(minPeople);
                mServiceInfo.setMaxbuyerNum(maxPeople);
                mOrderPersonNumContent.setmRightText(bindPersonNum(minPeople, maxPeople));
            }
        });
        showDialogFragment(selectTwoMenuFragment);
    }

    @OnClick(R.id.il_pricing_type)
    public void setPricingType() {
        ChoiceDialog dialog = ChoiceDialog.getInstance();
        dialog.setDialogTitleVisibility(false);
        List<MultiItem> multiItemList = new ArrayList<MultiItem>();
        String[] hostArray = getResources().getStringArray(R.array.pay_ways_array);
        for (String apiString : hostArray) {
            MultiItem multiItem = new MultiItem(apiString);
            multiItemList.add(multiItem);
        }
        dialog.setDialogMessageVisibility(false);
        dialog.setDialogMultiStyleSetting(multiItemList, new ChoiceDialog.DialogStyleMultiCallback() {
            @Override
            public boolean onMultiItemClick(MultiItem multiItem, int position) {
                if (!TextUtils.isEmpty(multiItem.getItemTitle())) {
                    priceType = position + "";
                    mServiceInfo.setPriceType(priceType);
                    updatePriceType();
                    bindPayType(multiItem.getItemTitle());
                }
                return false;
            }
        });
        showDialogFragment(dialog);
    }

//

    @OnClick(R.id.il_currency)
    public void setCurrency() {
        showLoading();
        OrderBusiness.getRates(mApiProxy, 0, 20);
    }

    private void initAdvanceDayList() {
        for (int i = 1; i <= ADVANCE_DAY; i++) {
            advanceDayList.add(i);
        }
    }

    private void initDurationList() {
        for (int i = 0; i <= 23; i++) {
            StringBuilder stringBuilder = new StringBuilder();
            if (i < 10) {
                stringBuilder.append(0).append(i);
            } else {
                stringBuilder.append(i);
            }
            stringBuilder.append(":00");
            SelectMenu selectMenu = new SelectMenu();
            selectMenu.key = String.valueOf(i);
            selectMenu.value = stringBuilder.toString();
            timeList.add(selectMenu);
        }
    }

    private void initPeopleList() {
        for (int i = 1; i <= 6; i++) {
            SelectMenu minPeopleMenu = new SelectMenu();
            minPeopleMenu.key = String.valueOf(i);
            minPeopleMenu.value = TextProxy.getInstance().formatWithSingleAndMore(i, R.string.trip_attribute_capacity_value_min_one, R.string.trip_attribute_capacity_value_min_more);
            minPeopleMenuList.add(minPeopleMenu);

            SelectMenu maxPeopleMenu = new SelectMenu();
            maxPeopleMenu.key = String.valueOf(i);
            maxPeopleMenu.value = TextProxy.getInstance().formatWithSingleAndMore(i, R.string.trip_attribute_capacity_value_max_one, R.string.trip_attribute_capacity_value_max_more);
            maxPeopleMenuList.add(maxPeopleMenu);
        }
    }

    private void bindPreOrderDays() {
        String text = TextProxy.getInstance().formatWithSingleAndMore(mServiceInfo.getPreOrderDays(), R.string.trip_attribute_advance_value_one, R.string.trip_attribute_advance_value_more);
        mOrderAdvanceNum.setmRightText(text);
    }

    private void bindDuration() {
        String text = TextProxy.getInstance().formatWithSingleAndMore(mServiceInfo.getServiceTime(), R.string.trip_attribute_duration_value_one, R.string.trip_attribute_duration_value_more);
        mOrderDuration.setmRightText(text);
    }

    private void bindPayType(String text) {
        if (text == null) {
            mOrderPricingType.setmRightText("");
        } else {
            mOrderPricingType.setmRightText(text);
        }
    }

    @Override
    public boolean onProxyResult(ProxyResult<?> result) {
        CtApiResponse response = (CtApiResponse) result.getData();
        if (response.isResponseNormal()) {
            hideLoading();
            if (ApiManager.GET_RATES.equals(response.getApiName()) && response.result instanceof List) {
                List<Rate> rateList = (List<Rate>) response.result;
                boolean hasUSD = false;
                for (int i = 0; i < rateList.size(); i++) {
                    Rate rate = rateList.get(i);
                    if ("USD".equalsIgnoreCase(rate.currency)) {
                        hasUSD = true;
                    }
                }
                if (!hasUSD) {
                    Rate usd = new Rate("", "", "USD");
                    rateList.add(0, usd);
                }
                PriceProxy.getInstance().showCurrencySelect(getHostActivity(), rateList, new PriceProxy.CurrencyCallback() {
                    @Override
                    public void onCurrencySelect(String currency) {
                        mOrderCurrency.setmRightText(currency);
                        tvCurrency.setText(currency);
                    }
                });
            } else if (ApiManager.GET_INFOPAGES.equals(response.getApiName()) && response.result instanceof PayMode) {
                PayMode payMode = (PayMode) response.result;
                notice = payMode.getNotice();

            } else {
                if (TextUtils.isEmpty(response.msg)) {
                    ToastUtil.toast(response.msg);
                }
            }
        }
        return false;
    }


    private void updatePriceType() {
        if (priceType.equals(ServiceInfo.PAYWAY_FREE)) {
            mPayCountContent.setVisibility(View.GONE);
            mPriceLayout.setVisibility(View.GONE);
            mOrderCurrency.setVisibility(View.GONE);
        } else if (priceType.equals(ServiceInfo.PAYWAY_PER)) {
            mPayCountContent.setVisibility(View.VISIBLE);
            mMoneyEndView.setVisibility(View.VISIBLE);
            mOrderCurrency.setVisibility(View.VISIBLE);
            mPriceLayout.setVisibility(View.VISIBLE);
        } else if (priceType.equals(ServiceInfo.PAYWAY_ALL)) {
            mPayCountContent.setVisibility(View.VISIBLE);
            mMoneyEndView.setVisibility(View.GONE);
            mOrderCurrency.setVisibility(View.VISIBLE);
            mPriceLayout.setVisibility(View.VISIBLE);
        }
    }

    private void bindValueToLayout(int... types) {
        for (int type : types) {
            setValueInContent(type);
        }
    }

    private void setValueInContent(int contentType) {
        switch (contentType) {
            case PAY_TYPE:
                if (!TextUtils.isEmpty(priceType)) {
                    int priceIndex = Integer.parseInt(priceType);
                    bindPayType(getResources().getStringArray(R.array.pay_ways_array)[priceIndex]);
                } else {
                    bindPayType(null);
                }
                break;
            case PRICE_TYPE:
                bindPrice(price);
                break;
            case PAY_INCLUDE_TYPE:
                setValueToLayout(priceIncludeLayout, includePayList);
                break;
            case PAY_EXCLUDE_TYPE:
                setValueToLayout(priceExcludeLayout, excludePayList);
                break;
            case PAY_CURRENCY_TYPE:
                mOrderCurrency.setmRightText(mServiceInfo.getMoneyType());
                tvCurrency.setText(mServiceInfo.getMoneyType());
                break;

        }
    }

    private void bindPrice(String text) {
        if (TextUtils.isEmpty(text)) {
            return;
        }
        String formatText = NumberUtils.getMoneyFormat(text);
        mPayCountContent.setText(formatText);
        mPayCountContent.setSelection(formatText.length());
    }

    private void setValueToLayout(EditDetailLayout editDetailLayout, List<CharSequence> paraTextList) {
        List<Para> paraList = new ArrayList<>();
        if (!ArrayUtil.isNullOrEmpty(paraTextList)) {
            for (CharSequence charSequence : paraTextList) {
                Para para = new Para(charSequence);
                paraList.add(para);
            }
        }
        editDetailLayout.setParaList(paraList);
    }


    private void initValues() {
        if (mServiceInfo != null) {
            if (!TextUtils.isEmpty(mServiceInfo.getPriceType())) {
                priceType = mServiceInfo.getPriceType();
            } else {
                priceType = ServiceInfo.PAYWAY_FREE;
            }
            if (!TextUtils.isEmpty(mServiceInfo.getPrice())) {
                price = mServiceInfo.getPrice();
            }
            if (!TextUtils.isEmpty(mServiceInfo.getFeeExclude())) {
                excludePayList.clear();
                excludePayList.addAll(ParaProxy.getInstance().getParaList(mServiceInfo.getFeeExclude()));
            }
            if (!TextUtils.isEmpty(mServiceInfo.getFeeInclude())) {
                includePayList.clear();
                includePayList.addAll(ParaProxy.getInstance().getParaList(mServiceInfo.getFeeInclude()));
            }
            if (TextUtils.isEmpty(mServiceInfo.getMoneyType())) {
                mServiceInfo.setMoneyType(UnitUtils.getSettingMoneyType().toUpperCase());
            }

            if (mServiceInfo.getPreOrderDays() != 0) {
                bindPreOrderDays();
            }
            if (!TextUtils.isEmpty(mServiceInfo.getServiceTime())) {
                bindDuration();
            }
            if (mServiceInfo.getMaxbuyerNum() != 0 && mServiceInfo.getMinBuyerNum() != 0) {
                int minPeople = mServiceInfo.getMinBuyerNum();
                int maxPeople = mServiceInfo.getMaxbuyerNum();
                mOrderPersonNumContent.setmRightText(bindPersonNum(minPeople, maxPeople));
            }

        }


    }

    private int getPrice() {
        return (int) NumberUtils.parseFloat(mPayCountContent.getText().toString());
    }

    /**
     * 选择返回键依然要保存数据
     *
     * @param fromKey
     * @return
     */
    @Override
    public boolean onBackPressed(boolean fromKey) {
        saveAction();
        InputMethodManager ma = (InputMethodManager) getHostActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
        if (getHostActivity().getCurrentFocus() != null) {
            ma.hideSoftInputFromWindow(getHostActivity().getCurrentFocus().getApplicationWindowToken(), 0);
        }
        return super.onBackPressed(fromKey);
    }

    private void saveAction() {
        //计费方式
        mServiceInfo.setPriceType(priceType);
        //费用
        mServiceInfo.setPrice(getPrice() + "");
        //货币类型
        mServiceInfo.setMoneyType(mOrderCurrency.getmRightText().toString());
        mServiceInfo.setFeeInclude(ParaProxy.getInstance().outputPara(includePayList));

        mServiceInfo.setFeeExclude(ParaProxy.getInstance().outputPara(excludePayList));
        RxBus.getDefault().send(new ServiceChangeEvent(FormType.PAY));
    }

    @Override
    public void onTopbarLeftPress() {
        onBackPressed(false);
    }

    @Override
    public void onTopbarRightPress() {
        WebViewProxy.getInstance().browseWeb(getHostActivity(), WalletHelpDocProxy.formatUrl(H5UrlMaker.getWalletSettingPriceUrl()), false);

    }

    public void onDestroy() {
        super.onDestroy();
    }


}
